﻿using System;

using PostSharp.Laos;

namespace Exif.Aspects
{
	///<summary>
	///Аспект на вызов отдельно геттера и сеттера.
	///</summary>
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Struct)]
	public class OnPropertyInvocationAspect : OnMethodInvocationAspect
	{
		///<summary>Method called instead of the intercepted method.</summary>
		///<param name="eventArgs">Event arguments specifying which method is being
		///executed and which are its arguments. The implementation should set the return
		///value and output arguments.</param>
		public sealed override void OnInvocation(MethodInvocationEventArgs eventArgs)
		{
			if(eventArgs.Delegate.Method.Name.ToLower().StartsWith("get_"))
			{
				this.Getter(eventArgs);
			}
			else if (eventArgs.Delegate.Method.Name.ToLower().StartsWith("set_"))
			{
				this.Setter(eventArgs);
			}

			eventArgs.Proceed();
		}

		///<summary>
		///Вызов сеттера
		///</summary>
		///<param name="eventArgs"></param>
		protected virtual void Setter(MethodInvocationEventArgs eventArgs)
		{
			eventArgs.Proceed();
		}

		///<summary>
		///Вызов геттера
		///</summary>
		///<param name="eventArgs"></param>
		protected virtual void Getter(MethodInvocationEventArgs eventArgs)
		{
			eventArgs.Proceed();
		}
	}
}